home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / lbbs07 / sysdep.c < prev    next >
C/C++ Source or Header  |  1993-07-06  |  5KB  |  293 lines

  1. /* 
  2.  *    BBS Level Zero - System Dependant Functions
  3.  *    (LazyBBS Project)
  4.  *
  5.  *    Public Domain: may be copied and sold freely
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. #ifdef UNIX
  13. #include <termios.h>
  14. #include <sys/ioctl.h>
  15. #include <fcntl.h>
  16. #define RZ_PROG        "rz"
  17. #define SZ_PROG        "sz"
  18. #endif
  19.  
  20. #ifdef ATARI
  21. #include <ext.h>    /* sleep */
  22. #define RZ_PROG        "rz.ttp"
  23. #define SZ_PROG        "sz.ttp"
  24. #endif
  25.  
  26. #include "bbs.h"
  27. #include "sysdep.h"
  28.  
  29. /*
  30.  *    DOWNLOAD routines
  31.  */
  32.  
  33. #ifdef ATARI
  34.  
  35. int z_upload(char *a)
  36. {
  37.     char temp[BBSSTR];
  38.     int ret;
  39.     
  40.     if(getcwd(temp,BBSSTR))
  41.     {
  42.         chdir(a);
  43.         ret=forklp(RZ_PROG,RZ_PROG,NULL);
  44.         if(!ret)
  45.             ret=wait();
  46.         chdir(temp);
  47.     }
  48.     return ret;
  49. }
  50.  
  51. int z_download(char *a)
  52. {
  53.     int ret;
  54.     
  55.     ret=forklp(SZ_PROG,SZ_PROG,a,NULL);
  56.     if(!ret)
  57.         ret=wait();
  58.     return ret;
  59. }
  60.  
  61. #endif
  62.  
  63. /*
  64.  *    ATARI ST Low level routines
  65.  */
  66.  
  67. #ifdef ATARI
  68.  
  69. #include <osbind.h>
  70.  
  71. #ifndef WORD
  72. #define WORD short
  73. #endif /* WORD */
  74.  
  75. #define AUXDEVICE 1
  76. #define CONDEVICE 2
  77.  
  78. int dupeio=0;
  79. int aux_device=AUXDEVICE;
  80.  
  81. int sysdep_dupeio(char *s)
  82. {
  83.     if(atoi(s)>1)
  84.         aux_device=atoi(s);
  85.     dupeio++;
  86.     sysdep_flushin();
  87.     return BBSOK;
  88. }
  89.  
  90. void sysdep_flushin(void )
  91. {
  92.     while(Bconstat(CONDEVICE)) Bconin(CONDEVICE);
  93.     if(dupeio)
  94.         while(Bconstat(aux_device)) Bconin(aux_device);
  95. }
  96.  
  97. /* get char */
  98.  
  99. int sysdep_getchar(unsigned char *ret)
  100. {
  101.     if(Bconstat(CONDEVICE))
  102.     {    
  103.         *ret=(unsigned char) Bconin(CONDEVICE);
  104.         return BBSOK;
  105.     }
  106.     if(dupeio)
  107.     {
  108.         if(Bconstat(aux_device))
  109.         {
  110.             *ret=(unsigned char) Bconin(aux_device);
  111.             return BBSOK;
  112.         }
  113.     }
  114.     
  115.     return BBSFAIL;
  116. }
  117.  
  118. void sysdep_putchar(unsigned char truc)
  119. {
  120.     while(Bcostat(CONDEVICE)==0) ; /* wait for readyness */
  121.     Bconout(CONDEVICE,(WORD) truc);
  122.         
  123.     if(dupeio)
  124.     {
  125.         while(Bcostat(aux_device)==0)
  126.         {
  127.             if(sysdep_carrier()) /* don't lock */
  128.                 return;
  129.         }
  130.         
  131.         Bconout(aux_device,(WORD) truc);
  132.     }
  133. }
  134.  
  135. /* watch carrier */
  136.  
  137. int sysdep_carrier() /* Steve Yellington */
  138. {
  139.     void *ssp;
  140.     register WORD *mfp, status;
  141.     mfp = ((WORD *) 0xFFFFFA00L);        /* base address of MFP */
  142.     ssp = Super(NULL);                  /* enter supervisor mode */
  143.     status = *mfp;                      /* get MFP status */
  144.     Super(ssp);                         /* return to user mode */
  145.     return((int)status & 0x0002);             /* check for carrier */
  146. }
  147.  
  148. /* hang up */
  149.  
  150. void sysdep_hangup(void )
  151. {
  152.     Ongibit(0x10);          /* dtr off */
  153.     sleep(1);             /* wait one second */
  154.     Offgibit(0xEF);        /* dtr on */
  155. }
  156.  
  157. #endif /* ATARI */
  158.  
  159. /*
  160.  *     UNIX sysdep io 
  161.  */
  162.   
  163. #ifdef UNIX
  164.   
  165. int unix_line=-1;
  166.   
  167. int z_download(char *s)
  168. {
  169.      char str[200];
  170.  
  171.      sprintf (str, "%s %s", SZ_PROG, s);
  172.      return system (str);
  173. }
  174.  
  175. int z_upload(char *s)
  176. {
  177.      char str[200];
  178.  
  179.      sprintf (str, "%s %s", RZ_PROG, s);
  180.      return system (str);
  181. }
  182.  
  183. int sysdep_dupeio(char *device)
  184. {
  185.       struct termios tios;
  186.       
  187.       unix_line=open(device,O_RDWR|O_NDELAY,0);
  188.       if(unix_line<0)
  189.          return BBSFAIL;
  190.      tcgetattr(unix_line,&tios);
  191.      tios.c_iflag|= IGNBRK;
  192.      tios.c_cflag|= B0 | CS8 | CREAD | CLOCAL | CRTSCTS;
  193.      tios.c_lflag|= NOFLSH+ECHO;
  194.      tios.c_lflag&= ~(ICANON+ECHOCTL);
  195.  
  196.       if(tcsetattr(unix_line,TCSANOW,&tios))
  197.       {
  198.           perror("lazybbs - tcsetattr");
  199.           return BBSFAIL;
  200.       }
  201.      out_string("coucou\n");
  202.      return BBSOK;
  203. }
  204.   
  205. void sysdep_flushin(void)
  206. {
  207.     int nbchar;
  208.      char c;
  209.      
  210.      if (unix_line!=-1) {
  211.          if(ioctl(unix_line,FIONREAD,&nbchar)<0)
  212.              perror("lazybbs - fionread");
  213.          while (nbchar--)
  214.              read(unix_line,&c,1);
  215.      }
  216.      if(ioctl(0,FIONREAD,&nbchar)<0)
  217.          perror("lazybbs - fionread");
  218.      while (nbchar--)
  219.          read(0,&c,1);
  220. }
  221.   
  222. int sysdep_getchar(unsigned char *ret)
  223. {
  224.       int nbchar=0;
  225.       
  226.       if(unix_line!=-1)
  227.       {
  228.         if(ioctl(unix_line,FIONREAD,&nbchar)<0)
  229.               perror("lazybbs - fionread");    
  230.           if(nbchar>0)
  231.              if(read(unix_line,ret,1)==1) {
  232.                  putchar(*ret); /* echo sur ligne locale */
  233.                   return BBSOK;
  234.              }
  235.       }
  236.  
  237.      /* if no unix_line or no char, check stdin */
  238.      
  239.      if(ioctl(0,FIONREAD,&nbchar)<0)
  240.          perror("lazybbs - fionread");    
  241.      if(nbchar>0)
  242.          if(read(0,ret,1)==1) {
  243.              if(unix_line!=-1)
  244.                  write(unix_line,ret,1);    /* echo sur distant */
  245.               return BBSOK;
  246.          }
  247.       
  248.       return BBSFAIL;
  249. }
  250.  
  251. void sysdep_putchar(unsigned char truc)
  252. {
  253.     putchar(truc);
  254.     if(unix_line!=-1)
  255.     {
  256.         /* fixme? never block? */
  257.         if(write(unix_line,&truc,1)==-1)
  258.             perror("lazybbs - write sysdep error");
  259.     }
  260. }
  261.  
  262. int sysdep_carrier(void )
  263. {
  264.     int tmp=0;
  265.     
  266.     if(unix_line!=-1)
  267.     {
  268.         if(ioctl(unix_line,TIOCMGET,&tmp)<0)
  269.             return 0;
  270.         return ( (tmp & TIOCM_CD)==0 );
  271.     }
  272.     return 1;
  273. }
  274.  
  275. void sysdep_hangup(void )
  276. {
  277.     int set_stat_line;
  278.     
  279.     if(unix_line!=-1)
  280.     {
  281.         set_stat_line=TIOCM_DTR;
  282.         if(ioctl(unix_line,TIOCMBIC,&set_stat_line)<0)
  283.             perror("lazybbs - dtr off");    
  284.         sleep(1);
  285.         set_stat_line=TIOCM_DTR;
  286.         if(ioctl(unix_line,TIOCMBIS,&set_stat_line)<0)
  287.             perror("lazybbs - dtr on");
  288.     }
  289. }
  290.  
  291. #endif /* UNIX */
  292.  
  293. /* eof */